﻿Imports System
Imports Microsoft.VisualBasic
Imports ChartDirector
Public Class frmAfternoon6pm
    Private Sub frmAfternoon6pm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        ' SQL statement.
        Dim SQL As String = _
            "Select fldAfternoon6pm From tblComparison"

        Dim SQL2 As String = _
            "Select fldDate From tblComparison"

        '
        ' Connect to database and read the query result into arrays
        '

        ' In this example, we use OleDbConnection to connect to MS Access (Jet Engine).
        ' If you are using MS SQL, you can use SqlConnection instead of OleConnection.
        Dim dbconn As System.Data.IDbConnection = _
            New System.Data.OleDb.OleDbConnection( _
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PsychologicalStateTracker.mdb;")

        dbconn.Open()

        ' Set up the SQL statement
        Dim sqlCmd As System.Data.IDbCommand = dbconn.CreateCommand()
        sqlCmd.CommandText = SQL

        Dim sqlCmd2 As System.Data.IDbCommand = dbconn.CreateCommand()
        sqlCmd2.CommandText = SQL2

        ' Read the data into the DBTable object
        Dim table As DBTable = New DBTable(sqlCmd.ExecuteReader())

        Dim table2 As DBTable = New DBTable(sqlCmd2.ExecuteReader())
        dbconn.Close()

        ' Get the data as arrays
        Dim dblAfternoon6pm() As Double = table.getCol(0)

        Dim dblDate() As Double = table2.getCol(0)

        '
        ' Now we have read data into arrays, we can draw the chart using ChartDirector
        '

        ' Create a XYChart object of size 600 x 300 pixels, with a light grey (eeeeee)
        ' background, black border, 1 pixel 3D border effect and rounded corners.
        Dim c As XYChart = New XYChart(1160, 625, &HEEEEEE, &H0, 1)
        c.setRoundedFrame()

        ' Set the plotarea at (60, 60) and of size 520 x 200 pixels. Set background color
        ' to white (ffffff) and border and grid colors to grey (cccccc)
        c.setPlotArea(60, 60, 1000, 500, &HFFFFFF, -1, &HCCCCCC, &HCCCCCCC)

        ' Add a title to the chart using 15pts Times Bold Italic font, with a light blue
        ' (ccccff) background and with glass lighting effects.
        c.addTitle("Comparison - Afternoon (6pm) ", _
            "Times New Roman Bold Italic", 15).setBackground(&HCCCCFF, &H0, _
            Chart.glassEffect())

        ' Add a legend box at (70, 32) (top of the plotarea) with 9pts Arial Bold font
        c.addLegend(70, 32, False, "Arial Bold", 9).setBackground(Chart.Transparent)

        ' Add a stacked line chart layer using the supplied data
        Dim layer As Layer = c.addLineLayer(Chart.Stack)
        layer.addDataSet(dblAfternoon6pm, &HFF0000, "Score")

        ' Use soft lighting effect with light direction from the left
        layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Left))

        ' Set the x axis labels.
        Dim labels() As Double = dblDate
        c.xAxis().setLabels(labels)

        ' Draw the ticks between label positions (instead of at label positions)
        c.xAxis().setTickOffset(0.5)

        'Set the x axis title
        c.xAxis().setTitle("Period")

        ' Set the y axis title
        c.yAxis().setTitle("Score (max 12)")

        ' Set axis width to 2 pixels
        c.xAxis().setWidth(2)
        c.yAxis().setWidth(2)

        ' Output the chart in PNG format
        WinChartViewer1.Image = c.makeImage()

        ' Include tool tip for the chart
        WinChartViewer1.ImageMap = c.getHTMLImageMap("", "", _
            "title='Comparison - Afternoon (6pm)'")

    End Sub
End Class